//
//  SongListTableViewCell.m
//  Education
//
//  Created by 流风幻雾 on 15/7/16.
//  Copyright (c) 2015年 HUA. All rights reserved.
//

#import "SongListTableViewCell.h"

@implementation SongListTableViewCell

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if(self)
    {
        self.leftImageView = [[UIImageView alloc]initWithFrame:CGRectMake(kScreenWidth * 0.053, kScreenWidth * 0.013, 60, 60)];
        self.leftImageView.image = [UIImage imageNamed:@"pencil.jpg"];
        [self.contentView addSubview:_leftImageView];
        self.titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(self.leftImageView.frame.origin.x + self.leftImageView.frame.size.width + kScreenWidth * 0.053, kScreenWidth * 0.013, kScreenWidth - 150, 50)];
        self.titleLabel.text = @"摇篮曲";
        self.titleLabel.numberOfLines = 0;
        self.titleLabel.font = [UIFont fontWithName:nil size:13];
        [self.contentView addSubview:self.titleLabel];
        self.timeCountLabel = [[UILabel alloc]initWithFrame:CGRectMake(_titleLabel.frame.origin.x , 40, 80, 25)];
        self.timeCountLabel.text = @"3:01";
        self.timeCountLabel.font = [UIFont fontWithName:nil size:13];
        [self.contentView addSubview:_timeCountLabel];
        self.dataSizeLabel = [[UILabel alloc]initWithFrame:CGRectMake(self.timeCountLabel.frame.origin.x + self.timeCountLabel.frame.size.width + 15, 40, 80, 25)];
        self.dataSizeLabel.text = @"0.5M";
        self.dataSizeLabel.font = [UIFont fontWithName:nil size:13];
        self.dataSizeLabel.textAlignment = NSTextAlignmentCenter;
        [self.contentView addSubview:_dataSizeLabel];
    }
    return self;
}



- (void)setValueWithModel:(SongListTableViewCellModel *)model
{
    [self.leftImageView sd_setImageWithURL:[NSURL URLWithString:model.coverLarge] placeholderImage:[UIImage imageNamed:@"kidsEnglish"] completed:nil];
    self.titleLabel.text = model.title;
    self.timeCountLabel.text = [self setValueWithString:model.duration];
    self.dataSizeLabel.text = [self setSizeValueWithString:model.mp3size_64];
}

//时间转时钟形式
- (NSString *)setValueWithString:(NSString *)str
{
    int temp = [str intValue];
    int MinuteNum = temp / 60;
    int SecondNum = temp - MinuteNum * 60;
    NSString *SecondNumStr = [NSString stringWithFormat:@"%@",[NSNumber numberWithInt:SecondNum]];
    if(SecondNum < 10)
    {
        SecondNumStr = [NSString stringWithFormat:@"0%@",[NSNumber numberWithInt:SecondNum]];
    }
    return  [NSString stringWithFormat:@"%@:%@",[NSNumber numberWithInt:MinuteNum],SecondNumStr];
}

//字符串转文件大小
- (NSString *)setSizeValueWithString:(NSString *)str
{
    float temp = [str floatValue];
    float size = temp / (1024 * 1024);
    NSString *string = [NSString stringWithFormat:@"%.1fM",size];
    return string;
}
@end
